﻿using GameLibrary.Model;
using GameLibrary.Model.Core;
using GameLibrary.Model.Enums;
using G.Runtime;

namespace GameDesigner.Source.Test
{
    public class CoinFight
    {
        
        public static void Build(GameDef game)
        {
            game.Name = "Coin Fight";
            {
                GameElementDef element = GameDefFactory.Factory.CreateElement(
                    game, new GameLocation(1, 1));
                element.Player = "Player1";
                game.GameElementDefs.Add(element);
            }
            {
                GameElementDef element = GameDefFactory.Factory.CreateElement(
                    game, new GameLocation(5, 1));
                element.Player = "Player2";
                game.GameElementDefs.Add(element);
            }
            {
                GameElementDef element = GameDefFactory.Factory.CreateElement(
                    game, new GameLocation(5, 2));
                element.Icon = "Coin";
                element.Player = "Nothing";
                element.CollisionStratagy = CollisionStratagyEnum.CONSUME;
                GameValueDef v = new GameValueDef();
                v.Value = "100";
                element.GameValueDefs.Add(v);
                game.GameElementDefs.Add(element);
                game.GameElementDefs.GameScriptDef.Text = @"
public class GameElementsDefs_Script
{
    private G.Runtime.GameElements _Subject;

    public GameElementsDefs_Script(G.Runtime.GameElements subject)
    {
        _Subject = subject;
        _Subject.Triggers.ConsumeEvent += OnConsumeEvent;
    }

    void OnConsumeEvent(G.Runtime.GameElement consumer, G.Runtime.GameElement consumee)
    {
        consumer.GameValues.Add(consumee.GameValues);
        consumer.Location = consumee.Location;
    }
}
";
                
                game.GamePlayerDefs.GameScriptDef.Text = @"
public class GamePlayerDefs_Script
{
    private G.Runtime.GamePlayers _Subject;

    public GamePlayerDefs_Script(G.Runtime.GamePlayers subject)
    {
        _Subject = subject;
        _Subject.Triggers.EndOfTurnEvent += OnEndOfTurnEvent;
    }

    void OnEndOfTurnEvent(G.Runtime.GameEvent turnEvent)
    {
    	 turnEvent.FireInvoke();
    }

}
";
            }
        }
        
    }
    
}
